package com.lm.liaoming.utils;

import android.content.Context;
import android.view.View;
import android.view.inputmethod.InputMethodManager;

/**
 * created by 韦敏敏
 * on 2019/11/26
 * 软件盘工具类
 */
public class SoftKeyboardUtil {
    private SoftKeyboardUtil() {
    }

    /**
     * 显示软键盘
     * @param context
     * @param input   必须是可输入的view， 例如EditText
     */
    public static void showSoftKeyboard(Context context, View input){
        if(context == null || input == null)
            return;
        ((InputMethodManager)context.getSystemService(Context.INPUT_METHOD_SERVICE)).showSoftInput(input, 0);
    }

    /**
     *隐藏软键盘
     * @param context
     * @param view  任意可见的View
     */
    public static void hideSoftKeyboard(Context context, View view){
        if(context == null || view == null)
            return;
        ((InputMethodManager)context.getSystemService(Context.INPUT_METHOD_SERVICE)).hideSoftInputFromWindow(view.getWindowToken(), 0);
    }

    /**
     *  切换软件盘：显示变隐藏，隐藏变显示
     * @param context
     */
    public static void toggleSoftKeyboard(Context context){
        ((InputMethodManager)context.getSystemService(Context.INPUT_METHOD_SERVICE)).toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);
    }
}
